let url_for_ws = (name) => `ws://${window.location.host}/--/{name}`
$$ = (v) => document.querySelector(v)
$$$ = (v) => document.querySelectorAll(v)
HTMLCollection.prototype.map = (v) => Array.from(this).map(v)
HTMLCollection.prototype.each = (v) => Array.from(this).forEach(v)
UT=(v,s,e)=> new Date(v).toISOString().slice(s,e)


class WsEx extends (WebSocket) {
  constructor(name, port) {
    let host = port ? `${window.location.hostname}:${port}` : window.location.host;
    super(`ws://${host}/--/${name}`)
  }
}
async function $query_json(url, data,success=v=>v.json(),error=undefined)  {
  return await fetch(url, {
    method: data?'POST':'GET', body: data?JSON.stringify(data):undefined,
    headers: data?{'content-type': 'application/json'}:undefined
  }).then(success,error)
}

async function $api(mfunc, data,success=v=>v.json(),error=undefined) {
  return await fetch(`/-/${mfunc}`, {
    method: data?'POST':'GET', body: data?JSON.stringify(data):undefined,
    headers: data?{'content-type': 'application/json'}:undefined
  }).then(success,error)
}
function padBlank(v) {
  return v === undefined ? '' : v
}

function throttle(func, wait) {
  let timeout = null;
  return function() {
    const context = this;
    const args = arguments;
    if (!timeout) {
      timeout = setTimeout(() => {
        timeout = null;
        func.apply(context, args);
      }, wait);
    }
  };
}

function auth(obj){
  new Request()
  fetch()
  obj.name.value
  obj.pswd.value
  return false;
}

